package com.eques.util

import android.Manifest

object Config {

    /**
     * 正服和测服appKey和appId
     */
    const val EQUES_SERVER_APPID = 101

    /**
     * 正式服务器 正式阶段使用 勿动
     */
    const val EQUES_SERVER_APPKEY = "PtVVhucKfA3G2tsoKKbkMN4qHgZ6Cpfi"
    const val EQUES_DEFAULT_DISTRIBUTE_IP_PORT = "distribute.ecamzone.cc" //正式

    /**
     * 测试服务器 测试阶段使用 勿动
     */
//    const val EQUES_SERVER_APPKEY = "fwXxdcL0vRvStzje53Yte17LRgM8TLpo"
//    const val EQUES_DEFAULT_DISTRIBUTE_IP_PORT = "testdistribute.ecamzone.cc"

    /**
     * 请求其他第三方接口 THIRD_BRAND_ID THIRD_APP_SECRET 根据申请替换
     */
    const val THIRD_BRAND_ID = 3// 默认品牌ID
    const val THIRD_SERVER_APPID = 117
    const val THIRD_APP_SECRET = "c24c01e690e6f2b49aa7ef357b68450c"
    const val SERVER_REQUEST_HTTPS = "https://"
//    const val APP_KEY="e8d68d2616429eeca3a9d0223d6b8f93 "
    /*****interface****/

    /**constants**/
    //Login State
    const val LOGIN_STATE = "login_state"

    //Main Server
    const val MAIN_ADDRESS = "server_ip"//此处key底层需要使用，尽可能不要变动

    //Sub Server
    const val SUB_ADDRESS = "server_ip_non_core"

    const val EQUES_USER_NAME = "eques_user_name"
    const val EQUES_USER_UID = "eques_user_uid"
    const val EQUES_USER_BID = "eques_user_bid"
    const val EQUES_USER_TOKEN = "token"
    const val EQUES_USER_KEY = "eques_key"
    const val ADDING_DEVICES_TYPE = "adding_device_type"
    const val PERFERS_WIFIACCOUNT = "perfers_wifiAccount" //shareperfer,WiFi账号

    const val BLUFI_PREFIX = "BLUFI"
    const val BID = "bid"
    const val TYPE = "type"

    const val TESTNAME = "testing"
    const val TESTKEY = "b142f1bdfff48188c5427e12bea7027e"

    /**
     * 宠物设备相关参数保存
     */
    const val ANIMAL_IS_OFFLINE = "OfflineRemind"
    const val INITIATIVE_DEL = "initiativeDelDev"
    const val IS_DEL_DEV = "isDelDev"

    const val DEVICE_ONLINE = 1 // 设备在线
    const val DEVICE_OFFLINE = 0 // 设备掉线
    const val DEVICE_SLEEP = 2 // 设备休眠

    /**
     * 设备升级返回
     */
    const val DEVICE_NOT_NEED_UPDATE = 0
    const val DEVICE_NEED_UPDATE = 1
    const val DEVICE_IS_UPDATING = 2
    const val DEVICE_UPDATE_FAILED_BATTERY_LOW = 3
    const val DEVICE_UPDATE_FAILED_MEMORY_LOW = 4
    const val DEVICE_UPDATE_FAILED_NO_SDCARD = 5

    //public final static String THIRD_PARTY_USER_LOGINED = "1";
    //public final static String THIRD_PARTY_USER_NOT_LOGINED = "0";
    /**
     * 设备是否需要更新
     */
    const val NOT_NEED_UPDATE = 0
    const val NEED_UPDATE = 2
    const val NEED_MANDATORY_UPGRADE = 1
    const val IS_UPDATING = 3

    /*Event Number*/
    const val PROGRESS_ERROR_CODE: Int = -1
    const val EVENT_LOGIN_STATE = 1
    const val EVENT_BDY_LIST = 2
    const val METHOD_CLOSE_LEFT_MENU_ADD_DEV_INTER = 3
    const val METHOD_METHOD_FINISH_ACTIVITY = 4 //绑定失败结果
    const val EVENT_FINISH_ACTIVITY = 8 //关闭页面
    const val EVENT_METHOD_RMBDY_RESULT = 9
    const val CLIENT_AUTO_LOGIN_CONNECT_COMPLETE = 10
    const val EVENT_DEVICE_LIST_REFRESH = 11
    const val EVENT_REFRESH_SEND_FOOD_SUCCES = 12
    const val EVENT_SHAOW_STATE = 13
    const val EVENT_SHAOW_SETTING = 14
    const val EVENT_REFRESH_GET_PLAN_SUCCES = 15 //获取喂食计划成功
    const val EVENT_REFRESH_SEND_FOOD_PLAN_SUCCES = 16
    const val METHOD_MCU_UPGRADE_RESULT = 17
    const val EVENT_SHADOW_SETTING_DATA_NOTIFY = 18 // 获取设备影子设置数据通知更新（E6唤醒机制）
    const val METHOD_METHOD_UPGRADE_RESULT = 19 //设备升级反馈
    const val EVENT_E1_UPGRADE_ONLINE_NOTIFY = 20 // E1上线通知
    const val INCOMING_CALL_PREVIEW = 21 // 门铃来电缩略图

    const val EVENT_UPDATE_SHAOW_SETTING_SUCCESS = 15//更新设备影子设置数据成功


    val PERMISSIONS_BLUE =
        arrayOf(Manifest.permission.BLUETOOTH_CONNECT, Manifest.permission.BLUETOOTH_SCAN)

    var PERMISSIONS_SD_RECORD_WRITE_STORAGE_33 = arrayOf(
        Manifest.permission.READ_MEDIA_AUDIO,
        Manifest.permission.READ_MEDIA_IMAGES,
        Manifest.permission.READ_MEDIA_VIDEO
    )

    //麦克风、录音权限
    val PERMISSIONS_RECORD_AUDIO = arrayOf(Manifest.permission.RECORD_AUDIO)

    //麦克风、录音、读写权限组合申请
    val PERMISSIONS_AUDIO_RECORD_READ_WRITE = arrayOf(
        Manifest.permission.RECORD_AUDIO,
        Manifest.permission.READ_EXTERNAL_STORAGE,
        Manifest.permission.WRITE_EXTERNAL_STORAGE
    )

    //相机权限
    val PERMISSIONS_CAMERA = arrayOf(Manifest.permission.CAMERA)

    //拨打权限
    val PERMISSIONS_CALL_PHONE = arrayOf(Manifest.permission.CALL_PHONE)

    //位置、定位权限
    val PERMISSIONS_LOCATION = arrayOf(
        Manifest.permission.ACCESS_COARSE_LOCATION,
        Manifest.permission.ACCESS_FINE_LOCATION
    )

    const val REGISTER_URL = "/eques/api/partner/register"

    /**
     * 获取注册URL
     */
    fun getRegisterUrl(
        serverNonCoreIpNew: String?
    ): String? {
        return StringHandler.replace(
            StringHandler.append(SERVER_REQUEST_HTTPS, serverNonCoreIpNew, REGISTER_URL)
        )
    }


    const val CHECK_COUNT_URL = "/eques/api/partner/get-token"

    /**
     * 检查账户是否存在
     */
    fun checkAccount(
        serverNonCoreIpNew: String?
    ): String? {
        return StringHandler.replace(
            StringHandler.append(SERVER_REQUEST_HTTPS, serverNonCoreIpNew, CHECK_COUNT_URL)
        )
    }


    private const val GET_SERVER_URL = "/distribute/get_server?appid=%s&secret=%s"

    /**
     *获取分发地址URL
     */
    fun getServerUrl(
        serverNonCoreIpNew: String?,
        appid: String?,
        secret: String?
    ): String? {
        return StringHandler.replace(
            StringHandler.append(SERVER_REQUEST_HTTPS, serverNonCoreIpNew, GET_SERVER_URL),
            appid, secret
        )
    }

    /**
     * 查询影子设置（E6）
     */
    private const val QUERY_E6_SHADOW_SETTINGS =
        "/eques/v2/app/get_shadow_settings?uid=%s&token=%s&deviceId=%s&lastUpdate="

    fun shadowSettingsQueryUrl(
        serverNonCoreIpNew: String?,
        uid: String?,
        token: String?,
        devId: String?,
        lastUpdate: String
    ): String? {
        var url: String? = null
        url = if (StringHandler.strIsEmpty(lastUpdate)) {
            StringHandler.replace(
                StringHandler.append(
                    SERVER_REQUEST_HTTPS,
                    serverNonCoreIpNew,
                    QUERY_E6_SHADOW_SETTINGS
                ),
                uid, token, devId
            )
        } else {
            StringHandler.replace(
                StringHandler.append(
                    SERVER_REQUEST_HTTPS,
                    serverNonCoreIpNew,
                    QUERY_E6_SHADOW_SETTINGS
                ),
                uid, token, devId
            ) + lastUpdate
        }
        return url
    }


    /**
     * 影子设置更新（E6）
     * 以 POST 方式发送以下设置更新
     * ContentType = application/json
     */
    private const val UPDATE_E6_SHADOW_SETTINGS = "/eques/v2/app/update_shadow_settings?uid=%s&token=%s&deviceId=%s"

    fun updateSettingsUrl(
        serverNonCoreIpNew: String?,
        uid: String?,
        token: String?,
        devId: String?
    ): String? {
        return StringHandler.replace(
            StringHandler.append(SERVER_REQUEST_HTTPS, serverNonCoreIpNew, UPDATE_E6_SHADOW_SETTINGS),
            uid, token, devId
        )
    }

    /**
     * 查询影子状态（E6）
     */
    private const val QUERY_E6_SHADOW_STATUS =
        "/eques/v2/app/get_shadow_state?uid=%s&token=%s&deviceId=%s"

    fun queryShadowStatusUrl(
        serverNonCoreIpNew: String?,
        uid: String?,
        token: String?,
        devId: String?
    ): String? {
        return StringHandler.replace(
            StringHandler.append(SERVER_REQUEST_HTTPS, serverNonCoreIpNew, QUERY_E6_SHADOW_STATUS),
            uid, token, devId
        )
    }

    private const val QUERY_MCU_VER = "/eques/icvss/fireware/check/%s/%s/%s/%s/%s"

    fun getQueryMcuVer(
        serverIp: String,
        uid: String,
        token: String,
        role: String,
        model: String,
        version: String
    ): String? {
        return StringHandler.replace(
            StringHandler.append(
                SERVER_REQUEST_HTTPS,
                serverIp,
                QUERY_MCU_VER
            ), uid, token, role, model, version
        )
    }


    const val E6_SHADOW_SETTINGS: String =
        "/eques/v2/app/update_shadow_settings?uid=%s&token=%s&deviceId=%s"

    fun shadowSettingsUpdateUrl(
        serverNonCoreIpNew: String?,
        uid: String?,
        token: String?,
        devId: String?
    ): String? {
        val url = StringHandler.replace(
            StringHandler.append(SERVER_REQUEST_HTTPS, serverNonCoreIpNew, E6_SHADOW_SETTINGS),
            uid, token, devId
        )
        return url
    }

    /**
     * 获取智能锁报警消息列表
     */
    private const val GET_E1PRO_OPEN_LOCK_ALARM_LIST =
        "/eques/api/get_smart_lock_alarm?uid=%s&token=%s&lock_id=%s&start_time=%s&end_time=%s&offset=%s&limit=%s"

    fun getE1ProOpenLockAlarmListUrl(
        serverIpNew: String?,
        uid: String?,
        token: String?,
        lock_id: String?,
        start_time: String?,
        end_time: String?,
        offset: String?,
        limit: String?
    ): String? {
        return StringHandler.replace(
            StringHandler.append(SERVER_REQUEST_HTTPS, serverIpNew, GET_E1PRO_OPEN_LOCK_ALARM_LIST),
            uid, token, lock_id, start_time, end_time, offset, limit
        )
    }


    /**
     * 获取智能锁开锁记录列表
     */
    private const val GET_E1PRO_OPEN_LOCK_RECORD_LIST =
        "/eques/api/get_lock_record?uid=%s&token=%s&lock_id=%s&start_time=%s&end_time=%s&offset=%s&limit=%s"

    fun getE1ProOpenLockRecordListUrl(
        serverIpNew: String?,
        uid: String?,
        token: String?,
        lock_id: String?,
        start_time: String?,
        end_time: String?,
        offset: String?,
        limit: String?
    ): String? {
        return StringHandler.replace(
            StringHandler.append(
                SERVER_REQUEST_HTTPS,
                serverIpNew,
                GET_E1PRO_OPEN_LOCK_RECORD_LIST
            ),
            uid, token, lock_id, start_time, end_time, offset, limit
        )
    }


    /**
     * 宠物消息列表
     */
    private const val GET_ANIMAL_MSG =
        "/eques/api/pet/list?uid=%s&token=%s&deviceId=%s&endTime=%s&startTime=%s"

    fun getAnimalMsgList(
        serverIp: String?,
        uid: String?,
        token: String?,
        startTime: String?,
        endTime: String?,
        bid: String?
    ): String? {
        return StringHandler.replace(
            StringHandler.append(SERVER_REQUEST_HTTPS, serverIp, GET_ANIMAL_MSG),
            uid, token, bid, endTime, startTime
        )
    }


    /**
     * 根据时间获取访客消息列表
     */
    private const val CLIENT_GET_VISITOR_MESSAGELIST =
        "/eques/api/%s?uid=%s&token=%s&device_id=%s" +
                "&start_time=%s&end_time=%s&offset=%s&limit=%s"

    private fun setGetVisitorMessageList(serverIp: String): String? {
        return StringHandler.append(
            SERVER_REQUEST_HTTPS,
            serverIp,
            CLIENT_GET_VISITOR_MESSAGELIST
        )
    }

    fun getVisitorMessageListUrl(
        serverIp: String?, messageType: String?, localId: String?, token: String?, bid: String?,
        startTime: String?, endTime: String?, offest: String?, limit: String?
    ): String? {
        val urlReq = StringHandler.replace(
            setGetVisitorMessageList(serverIp!!), messageType,
            localId, token, bid, startTime, endTime, offest, limit
        )
        return urlReq
    }




}
